Import mojo

Class yimTicker
	Field started:Bool = False
	Field milli:Int
	Field tickTime:Int
	
	Field callback:yimTickerCallBack = Null
	
	Method New(mills:Int, autoStart:Bool=False, _callback:yimTickerCallBack=Null)
		started = autoStart
		callback = _callback
		
		Reset(mills)
		
	End
	
	Method Reset(mills:Int)
		milli = mills
		If started
			Start()
		EndIf
	End
	
	Method Start()
		tickTime = Millisecs()+milli
		started = True
	End
	
	Method Stop()
		started = False
	End
	
	Method Ticked()
		If started And Millisecs() >= tickTime
			tickTime = Millisecs() + milli
			Return True
		EndIf
		Return False
	End
	
	Method Update()
		If Ticked()
			If callback
				callback.Call(Self)
			EndIf
		EndIf
	End
End

Class yimTickerCallBack
	Method Call(this:yimTicker)
	
	End
End